package com.example.receiptocr.home

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.receiptocr.bodys.responseBodys.ReceiptInfo
import com.example.receiptocr.viewModels.ReceiptUiState

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ReceiptCard(
    receipt: ReceiptInfo,
    onClick: () -> Unit = {}
) {
    Card(
        modifier = Modifier
            .fillMaxWidth()
            .padding(vertical = 8.dp)
            .clickable{onClick()},
    ) {
        Column(
            modifier = Modifier
                .padding(16.dp)
                .fillMaxWidth()
        ) {
            // 上半部分
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(bottom = 8.dp),
                horizontalArrangement = Arrangement.SpaceBetween
            ) {
                Column {
                    Text(
                        text = "票据类型",
                        fontSize = 12.sp,
                        color = Color.Gray
                    )
                    Text(
                        text = receipt.receiptName.toString(),
                        fontSize = 18.sp,
                        fontWeight = FontWeight.Bold
                    )
                }
                Column(horizontalAlignment = Alignment.End) {
                    Text(
                        text = "金额(元)",
                        fontSize = 12.sp,
                        color = Color.Gray
                    )
                    Text(
                        text = "¥${receipt.totalAmount}",
                        fontSize = 18.sp,
                        fontWeight = FontWeight.Bold,
                        color = MaterialTheme.colorScheme.primary
                    )
                }
            }

            Divider(
                modifier = Modifier.padding(vertical = 8.dp),
                color = Color.LightGray
            )

            // 下半部分
            Row(
                modifier = Modifier.fillMaxWidth(),
                horizontalArrangement = Arrangement.SpaceBetween
            ) {
                Column {
                    Text(
                        text = "商家名称",
                        fontSize = 12.sp,
                        color = Color.Gray
                    )
                    Text(
                        text = receipt.sellerName.toString(),
                        fontSize = 14.sp
                    )
                }
                Column(horizontalAlignment = Alignment.End) {
                    Text(
                        text = "开具日期",
                        fontSize = 12.sp,
                        color = Color.Gray
                    )
                    Text(
                        text = receipt.receiptDate.toString(),
                        fontSize = 14.sp
                    )
                }
            }
        }
    }
}